package com.intelligentcar.springboot.service.serverImpl;

import com.intelligentcar.springboot.bean.DataPersonTest;
import com.intelligentcar.springboot.bean.Station;
import com.intelligentcar.springboot.mapper.DataPersonTestMapper;
import com.intelligentcar.springboot.service.DataPersonTestServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Random;

@Service
public class DataPersonTestServerImpl implements DataPersonTestServer {
    @Autowired
    private DataPersonTestMapper dataPersonTestMapper;

    @Override
    public int addTopData() {
        Random rm = new Random();
        String time =new SimpleDateFormat("yyyy-MM-dd-HH:mm:ss").format(new Date());
        String time1 =new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        String time2=new SimpleDateFormat("HH:mm:ss").format(new Date());
        List<Station> list = dataPersonTestMapper.selectAllStation();
        List<DataPersonTest> list1 = dataPersonTestMapper.ifTodayData(time1);
        if (list1.size()>0){
        }else{
            if (list.size()>0){
                for (int i = 0; i<list.size(); i++){
                    DataPersonTest d = new DataPersonTest();
                    d.setAddTime(time);
                    d.setUpCarDate(time1);
                    d.setUpTime(time2);
                    d.setUpStation(list.get(i).getStationName());
                    int j = rm.nextInt(50);
                    d.setUpNum(j);
                    dataPersonTestMapper.addTopData(d);
                }
            }
        }
        return 1;
    }
}
